#ifndef BLINKERAPIS_H
#define BLINKERAPIS_H

#include <Blinker.h>

/*任务通信变量*/
EventGroupHandle_t  pc_poweron_event=xEventGroupCreate();//定义：BIT0: 使能电脑开机 BIT1: 使能电脑2开机
extern EventGroupHandle_t  pc_poweron_event;


BlinkerButton btn1("btn-27y");
BlinkerButton pc_poweron("pc_poweron");
BlinkerButton pc_poweron2("pc_poweron2");

void API_dataRead(const String &data);
void API_button1(const String &data);
void API_pc_poweron(const String &state);
void API_pc_poweron2(const String &state);


void Blinker_Init()
{
  BLINKER_DEBUG.stream(Serial);
  Blinker.begin("d896a387634f","","");
  Blinker.attachData(API_dataRead);

  /*Blinker APIs*/
  btn1.attach(API_button1);
  pc_poweron.attach(API_pc_poweron);
  pc_poweron2.attach(API_pc_poweron2);
}

void API_dataRead(const String &data)
{
  log_d("Blinker readString:",data);
  //Blinker.push("Hello blinker");
}

void API_button1(const String &state)
{
  if(state=="on")
  {
    //digitalWrite(WIFI_EN,HIGH);
    btn1.print("on");
  }
  else
  {
    //digitalWrite(WIFI_EN,LOW);
    btn1.print("off");
  }
}

void API_pc_poweron(const String &state)
{
  xEventGroupSetBits(pc_poweron_event,BIT0);
  pc_poweron.print("tap");
}

void API_pc_poweron2(const String &state)
{
  xEventGroupSetBits(pc_poweron_event,BIT1);
  pc_poweron2.print("tap");
}
#endif